package it.unisalento.appsalento.adapter;

import it.unisalento.R;
import it.unisalento.appsalento.model.Esame;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListaEsamiAdapter extends ArrayAdapter<Esame> {
	
	public ListaEsamiAdapter(Context context, int textViewResourceId,
			ArrayList<Esame> objects) {
        super(context, textViewResourceId, objects);
    }

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.row_libretto, null);
        
        TextView nomeEsame = (TextView)convertView.findViewById(R.id.nomeEsame);
        ImageView statoEsame = (ImageView)convertView.findViewById(R.id.statoEsame);
//        ImageButton statoApprovaizone = (ImageButton)convertView.findViewById(R.id.statoApprovaizone);
        
        Esame esame = getItem(position);
        
        nomeEsame.setText(esame.getNomeEsame());
        if(!"".equals(esame.getStato())){
       
	        String drawableStatoName = (esame.getStato().toLowerCase()); 
		    int imageStotoResource = convertView.getContext().getResources().getIdentifier(drawableStatoName, "drawable", convertView.getContext().getPackageName());
	
		    Drawable imageStato = convertView.getContext().getResources().getDrawable(imageStotoResource);
		    statoEsame.setImageDrawable(imageStato);
        }
       
        return convertView;
    }
	
	

}
